<%@ page import="pkg_customerManagement.*" %>
<%@ page import="java.util.*" %>

<%
    String id = (String) session.getAttribute("login");

    if (id == null) {
        out.println("<div class=\"subcriber-red\">You must be logged in.</div>");
    } else {

        int num_id = Integer.parseInt((String) session.getAttribute("login"));
%>
<div class="page-title">Account Details</div>
<div class="page-sub-title">Addresses</div>

<%
    AddressDatabaseFunctions aDF = new AddressDatabaseFunctions();

    ArrayList<Address> addresses = aDF.getAddresses(num_id);

    for (int i = 0; i < addresses.size(); i++) {
%>
<span class="scrollArea-address" >
<div class="address" > 
    <table border="0">
        <tbody>
            <tr>
                <form name="contact" method="post" action="UpdateAddress">
                <input type="hidden" value="<% out.print(addresses.get(i).getId());%>" name="address_id"/>
                <td>Address Line 1:<br/><div class="required-text">Required</div></td>
                <td><input id="namebox" type="text" name="line_one" value="<% out.print(addresses.get(i).getAddrLineOne());%>" width="150px"/></td>
            </tr>
            <tr>
                <td>Address Line 2:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="line_two" value="<% out.print(addresses.get(i).getAddrLineTwo());%>"  width="150px"/></td>
            </tr>
            <tr>
                <td>City:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="city" value="<% out.print(addresses.get(i).getCity());%>"  width="150px"/></textarea></td>
            </tr>
            <tr>
                <td>County:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="county" value="<% out.print(addresses.get(i).getCounty());%>"  width="150px"/></td>
            </tr>
            <tr>
                <td>Country:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="country" value="<% out.print(addresses.get(i).getCountry());%>"  width="150px"/></textarea></td>
            </tr>
            <tr>
                <td>Post Code:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="post_code" value="<% out.print(addresses.get(i).getPostCode());%>"  width="150px"/></td>
            </tr>
            <tr>
                <td></td>
                <td><input style="width: 120px;height: 30px;background: blue;" type="submit" value="Update Address" />
                </form></td>
            </tr>
            <tr>
                <td></td>
                <td><form method= "post" action="RemoveAddress">
                    <input type="hidden" value="<% out.print(addresses.get(i).getId());%>" name="address_id"/>
                    <input style="width: 120px;height: 30px;background: red;" type="submit" value="Remove Address" /></form>
                </td>
            </tr>
        </tbody>
    </table><br/>
<table border="0" style="width: 100%">
    <tbody>
        <tr>
            <td>
                Delivery Report
            </td>
        </tr>
        <tr>
            
            <td><form method= "post" action="delivery-report.jsp">
                    <input type="hidden" value="<% out.print(num_id);%>" name="address_id"/>
                    <input style="width: 120px;height: 30px;background: gray;" type="submit" value="Delivery Report" /></form>
            </td>
        </tr>
        
    </tbody>
</table>  
</div>
<br/>
<br/>
<%
    }
%>
<div class="add-address-title">Add New Address</div>
<div class="address" >
<form name="contact" method="post" action="AddAddress">    
    <table border="0">
        <tbody>
            <tr>
                <td>Address Line 1:<br/><div class="required-text">Required</div></td>
                <td><input id="namebox" type="text" name="line_one" width="150px"/></td>
            </tr>
            <tr>
                <td>Address Line 2:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="line_two"  width="150px"/></td>
            </tr>
            <tr>
                <td>City:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="city"  width="150px"/></textarea></td>
            </tr>
            <tr>
                <td>County:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="county" width="150px"/></td>
            </tr>
            <tr>
                <td>Country:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="country" width="150px"/></textarea></td>
            </tr>
            <tr>
                <td>Post Code:<br/><div class="required-text">Required</div></td>
                <td><input id="emailbox" type="text" name="post_code"  width="150px"/></td>
            </tr>
            <tr>
                <td></td>
                <td><input style="width: 120px;height: 30px;background: blue;" type="submit" value="Add Address" />
                </td>
            </tr>
        </tbody>
    </table>
</form>
</div>
</span>
<% } //end login check %>